/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 30;
    vc.extends({
        data: {
            aRoomDetailRoomFeeInfo: {
                fees: [],
                roomNum: '',
                allOweFeeAmount: '0',
                payObjs:[],
                payerObjIds: [],
                roomId:'',
                state:'2008001',
                totalAmount:0,
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('aRoomDetailRoomFee', 'switch', function (_data) {
                $that.aRoomDetailRoomFeeInfo.roomId = _data.roomId;
                $that._loadARoomDetailRoomFeeData(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('aRoomDetailRoomFee', 'paginationPlus', 'page_event',
                function (_currentPage) {
                    $that._loadARoomDetailRoomFeeData(_currentPage, DEFAULT_ROWS);
                });
            vc.on('aRoomDetailRoomFee', 'notify', function (_data) {
                $that._loadARoomDetailRoomFeeData(DEFAULT_PAGE, DEFAULT_ROWS);
            })
        },
        methods: {
            _loadARoomDetailRoomFeeData: function (_page, _row) {
                let param = {
                    params: {
                        page: _page,
                        row: _row,
                        payerObjId: $that.aRoomDetailRoomFeeInfo.roomId,
                        state:$that.aRoomDetailRoomFeeInfo.state
                    }
                };
                //发送get请求
                vc.http.apiGet('/fee.listAdminFee',
                    param,
                    function(json) {
                        let _json = JSON.parse(json);
                        $that.aRoomDetailRoomFeeInfo.total = _json.total;
                        $that.aRoomDetailRoomFeeInfo.records = _json.records;
                        $that.aRoomDetailRoomFeeInfo.fees = _json.fees;
                        vc.emit('aRoomDetailRoomFee','paginationPlus', 'init', {
                            total: _json.records,
                            currentPage: _page
                        });
                        let _totalAmount = 0.0;
                        _json.fees.forEach(item => {
                            _totalAmount += parseFloat(item.amountOwed);
                        })
                        $that.aRoomDetailRoomFeeInfo.totalAmount = _totalAmount.toFixed(2);
                        $that.$forceUpdate();
                    },
                    function() {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _qureyARoomDetailRoomFee: function () {
                $that._loadARoomDetailRoomFeeData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _getRoomAttrValue: function(_attrs, _specCd) {
                let _value = "";
                _attrs.forEach(item => {
                    if (item.specCd == _specCd) {
                        _value = item.value;
                        return;
                    }
                });
                return _value;
            },
            _getRoomDeadlineTime: function(_fee) {
                if (_fee.amountOwed == 0 && _fee.endTime == _fee.deadlineTime) {
                    return "-";
                }
                if (_fee.state == '2009001') {
                    return "-";
                }
                return vc.dateFormat(_fee.deadlineTime);
            },
            _getRoomEndTime: function(_fee) {
                if (_fee.state == '2009001') {
                    return "-";
                }
                return vc.dateFormat(_fee.endTime);
            },
            _chanagePayerObjId: function() {
                $that._loadARoomDetailRoomFeeData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _changeContractConfigId:function() {
                $that._loadARoomDetailRoomFeeData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _toAdminFeeDetail:function(_fee){
                vc.jumpToPage('/#/pages/fee/adminFeeDetail?feeId='+_fee.feeId);
            }
           
            
        }
    });
})(window.vc);